package com.exam.sacrifice.viewmodel;

import androidx.lifecycle.ViewModel;

import com.exam.commonbiz.net.BaseObserver;
import com.exam.commonbiz.net.BaseResponse;
import com.exam.commonbiz.net.ExceptionHandle;
import com.exam.commonbiz.net.XApi;
import com.exam.sacrifice.api.ApiService;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class FamilyTreeViewModel extends ViewModel {

    private IFamilyTreeCallBack familyTreeCallBack;

    public void setFamilyTreeCallBack(IFamilyTreeCallBack familyTreeCallBack) {
        this.familyTreeCallBack = familyTreeCallBack;
    }

    public void myFamilyTree() {

        XApi.get(ApiService.class)
                .myFamilyTree()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver() {

                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        if (familyTreeCallBack != null) {
                            familyTreeCallBack.onFamilyTreeCallBack();
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponeThrowable responeThrowable) {
                        if (familyTreeCallBack != null) {
                            familyTreeCallBack.onFamilyTreeCallBack();
                        }
                    }

                    @Override
                    public void onFinish() {

                    }

                });
    }
}
